<header class="header" style="height: 44px;">
    <div class="fix_nav">
        <div class="nav_inner">
            <a class="nav-left back-icon" href="javascript:history.go(-1);">返回</a>
            <div class="tit">结算</div>
        </div>
    </div>
</header>

<div class="container mb50">
    <div class="row">
        <ul class="list-group">
            <li class="list-group-item text-primary">订单信息</li>
            <?php foreach ($plist as $item):?>
            <li class="list-group-item hproduct clearfix ">
                <div class="list-group_12">
                    <div class="p-pic">
                        <a href="/product/detail/goods_id/<?=$item['product_id']?>.html">
                            <img src="<?=$item['product_thumb']?>" alt="<?= $item['product_name']?>" class="img-responsive">
                        </a>
                    </div>
                    <div class="p-info">
                        <a href="/product/detail/goods_id/<?=$item['product_id']?>.html">
                            <p class="p-title"><?= $item['product_name']?></p>
                            <p class="p-origin">
                                <em class="price">¥<?=price_format($item['price'])?></em>
                            </p>
                        </a>
                    </div>
                </div>
            </li>
            <?php endforeach;?>
        </ul>
<!--
        <div class="list-group">
            <p class="list-group-item text-primary">抵扣方式</p>
            <a href="javascript:" class="list-group-item">
                <span class="glyphicon glyphicon-menu-right right-icon" aria-hidden="true"></span>
                红包：
                <span class="gary pull-right">您有<em class="red">0</em>个可用，点击选择</span>
            </a>
            <a href="#" style="display:none;" class="list-group-item">
                <span class="glyphicon glyphicon-menu-right right-icon" aria-hidden="true"></span>代金券：
                <span class="badge">42</span>
            </a>
        </div>
-->
        <div class="list-group">
            <p class="list-group-item text-primary">支付方式</p>
            <div class="list-group-item">
                <span class="black">微信支付：</span><img src="/v2/images/buy_wx.jpg">
                <div class="icheck pull-right">
                    <input type="radio" name="payment"  checked id="wxpay" value="wxpay">
                    <label for="wxpay">
                        <span></span>
                    </label>
                </div>
            </div>

            <div class="list-group-item">
                <span class="black">支付宝支付：</span><img src="/v2/images/buy_zfb.jpg">
                <div class="icheck pull-right">
                    <input type="radio" name="payment" id="alipay" value="alipay">
                    <label for="alipay">
                        <span></span>
                    </label>
                </div>
            </div>

        </div>

        <input type="hidden" name="order_sn" id="order_sn" value=""/>
    </div>
</div>
<div class="fixed-foot">
    <div class="fixed_inner">
        <div class="pay-point black">
            实付款：<em class="red f22">￥<span id="totalPrice"><?=price_format($amount)?></span></em>
        </div>
        <div class="buy-btn-fix">
            <a href="javascript:;" id="J_payBtn" class="btn btn-danger btn-buy">提交订单</a>
        </div>
    </div>
</div>

<script type="application/javascript">
//支付
$('#J_payBtn').click(function(){
    var payment = $('input[name=payment]:checked').val();
    $('.J_payBtn').attr('disabled', true);
    $.post('/order/balance.html?'+Math.random(),
        {payment:payment},
        function(res){
        $('.J_payBtn').attr('disabled', false);
        if(res.status == 1){
             $('#order_sn').val(res.order_sn);

             if(payment != 'wxpay') {//非微信支付
                 location.href=res.url;//页面直接跳转
                 return false;
             } else {
                 before_wxpay(res.order_sn);
             }
        }else{

            $(".ui-loader").remove();
            floatNotify.simple(res.msg);
        }
    },'json');
});

function before_wxpay(order_sn)
{
    var url = '/order/dopay/sn/'+order_sn+'/code/wxpay.html';
    showPageLoadingMsg('请稍候...');
    $.post(url+'?'+Math.random(),{}, function(res){
        $(".ui-loader").remove();
        if(typeof (res) == 'object')
        {
            wx_pay(res,order_sn);
        } else {
            floatNotify.simple(res.msg);
        }
    },'json');
}
function wx_pay(res,order_sn)
{
    WeixinJSBridge.invoke('getBrandWCPayRequest',{
        "appId":res.appId,
        "timeStamp":res.timeStamp,
        "nonceStr":res.nonceStr,
        "package":res.package,
        "signType":res.signType,
        "paySign":res.paySign
    },function(res){
        if(res.err_msg == "get_brand_wcpay_request:ok" ) {
            showPageLoadingMsg('处理中...');

            setInterval(function(){check_pay(order_sn)},1000);
        } else {
            location.href='/order/pay/sn/'+order_sn+".html?backurl=/";
        }
    });
}

function check_pay(order_sn){
    $.post('/order/checkpay/sn/'+order_sn +'?'+Math.random(), function(res){
        if(res.status == 1)
        {
            window.location.href='/payment/return/sn/'+order_sn;
        }
    },'json');
}
</script>
